package com.lesserpand.rabbitmq.rabbitmq.service.impl;

import com.lesserpand.rabbitmq.rabbitmq.constant.RedisEnum;
import com.lesserpand.rabbitmq.rabbitmq.service.RabbitmqInitSkillService;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.data.redis.core.StringRedisTemplate;
import org.springframework.stereotype.Service;

import java.util.concurrent.TimeUnit;

/**
 * @author bailuo
 * @version 2.0
 * @Description TODO
 * @Date Created in 2019/1/16 18:59
 */
@Service("rabbitmqInitSkillService")
public class RabbitmqInitSkillServiceImpl implements RabbitmqInitSkillService {

    private static final Logger LOGGER = LoggerFactory.getLogger(RabbitmqInitSkillServiceImpl.class);

    @Autowired
    private StringRedisTemplate stringRedisTemplate;

    /**
     * 配置抢购商品，放入redis，理论上需要配置抢购活动的，分布式定时任务，后期处理
     *
     * @param proId   抢购商品id
     * @param skillId 抢购id
     * @param num     抢购数量
     * @return
     */
    @Override
    public String initSkill(Long proId, Long skillId, String num) {
        String key = RedisEnum.SKILL_KEY.getValue() + skillId + ":" + proId;
        stringRedisTemplate.opsForValue().set(key, num, 60, TimeUnit.MINUTES);
        LOGGER.info("缓存成功");
        return "缓存成功";
    }

}
